///////////////////////////////////////////////////////////////
/// $Id: hash_map_test.cc 37 2009-10-21 13:39:27Z tonyjobmails $
/// $Date: 2009-10-21 13:39:27 +0000 (Wed, 21 Oct 2009) $
/// $Author: tonyjobmails $
/// $Revision: 37 $
/// E-mail: tonyjobmails@gmail.com
/// filename: hash_map_test.cc
/// function: hash表测试
///////////////////////////////////////////////////////////////

#include <iostream>
#include "hashtable.h"

using namespace std;
using namespace tototoy;

int main()
{
	char key1[100] = "key1";
	hashmap<const char*, char*> hash_char_char;

	cout << "得到HASH表大小测试" << endl;
	cout << "HASH表大小为: " << hash_char_char.size() << endl;

	split_line(true);

	cout << "HASH表empty()函数测试" << endl;
	if(hash_char_char.empty())
	{
		cout << "HASH表为空" << endl;
	}
	else
	{
		cout << "HASH表非空" << endl;
	}

	split_line(true);

	/// 测试hashtable插入元素
	cout << "插入元素测试：" << endl;
	if(hash_char_char.insert(key1, "value1"))
	{
		cout << "插入[\"key1\",\"value1\"]成功!" << endl;

		split_line(true);

		char *value = NULL;
		cout << "查找元素测试：" << endl;
		if(hash_char_char.find(key1, value))
		{
			cout << "查找元素\"key1\"结果为: " << value << endl;
		}

		split_line(true);

		cout << "得到HASH表大小测试" << endl;
		cout << "HASH表大小为: " << hash_char_char.size() << endl;

		split_line(true);

		cout << "HASH表empty()函数测试" << endl;
		if(hash_char_char.empty())
		{
			cout << "HASH表为空" << endl;
		}
		else
		{
			cout << "HASH表非空" << endl;
		}

		split_line(true);

		cout << "remove函数测试" << endl;
		if(hash_char_char.remove(key1))
		{
			cout << "移除\"key1\"成功, HASH表大小为: " << hash_char_char.size() << endl;
		}

		split_line(true);

		cout << "测试clear函数" << endl;
		if(hash_char_char.insert("key2", "value2"))
		{
			cout << "插入[\"key2\",\"value2\"]成功!" << endl;
			hash_char_char.clear();
			cout << "清楚全部元素成功, HASH表大小为: " << hash_char_char.size() << endl;
		}

		split_line(true);
	}
	return 0;
}
